#include "comm.hpp"
#include "log.hpp"
using namespace std;

int main()
{
    Init in;
    //开始通信
    int fd = open(FIFO_FILE,O_RDONLY);
    if(fd < 0)
    {
        logmessage(Fatal, "error string: %s, error code: %d", strerror(errno), errno);
        exit(FIFO_OPEN_ERR);
    }
    logmessage(Info, "server open file sueccess, error string: %s, error code: %d", strerror(errno), errno);
    while(1)
    {
        char buffer[1024] = {0}; 
        ssize_t x = read(fd, buffer, sizeof(buffer) - 1);
        if(x > 0)
        {
            buffer[x] = 0;
            cout << "服务器收到客户端发送的消息："<< buffer <<endl;

        }
        else if(x == 0)
        {
            cout << "客户端关闭，服务器关闭" << endl;
            break;
        }
        else 
        {
            break;
        }
    }
    close(fd);
    return 0;
}